/************舟山必玩（活动）路由器*********************/
const express = require('express')
const pool = require('../pool')
const router = express.Router()
module.exports = router

//1.查询所有舟山必玩活动的接口
//GET /show
//测试地址:http://127.0.0.1:8080/v1/activity/show
router.get('/show',(req,res)=>{
	let sql = 'select * from activity'
	pool.query(sql,(err,result)=>{
		if(err) throw err
		res.send(result)
	})
})

//2.查询指定数量活动的接口
//GET /list
//请求参数:pageSize=2
//测试地址:http://127.0.0.1:8080/v1/activity/list?pageSize=2
router.get('/list',(req,res)=>{
	let ps = req.query.pageSize
	ps = ps?parseInt(ps):5
	let sql = 'select * from activity limit ?'
	pool.query(sql,[ps],(err,result)=>{
		if(err) throw err
		res.send(result)
	})
})

//3.添加查询一个活动的接口
//GET /showAct
// 请求参数：aid=1
// 测试地址：http://127.0.0.1:8080/v1/activity/showAct?aid=1
router.get('/showAct',(req,res,next)=>{
	let id = req.query.aid
	let sql = 'select * from activity where aid = ?'
	pool.query(sql,[id],(err,result)=>{
		if(err){
			return next(err)
		}
		res.send(result)
	})
})



